<?php echo $this->headLink()->appendStylesheet('/css/redmond/jquery-ui-1.8.5.custom.css') ?>
<?php echo $this->headLink()->appendStylesheet('/css/poshytip-1.0/tip-yellowsimple/tip-yellowsimple.css') ?>
<script type="text/javascript" src="/jquery/jquery-ui-1.8.5.custom.min.js"></script> 
<script type="text/javascript" src="/jquery/jquery.ui.core.js"></script> 
<script type="text/javascript" src="/jquery/jquery.ui.datepicker.js"></script> 
<script type="text/javascript" src="/jquery/jquery.validate.js"></script>
<script type="text/javascript" src="/jquery/jquery.blockUI.js"></script>
<?php
$paramYear = $this->year;
$paramMonth = $this->month;
function getmicrotime(){ 
    list($usec, $sec) = explode(" ",microtime()); 
    return ((float)$usec + (float)$sec); 
} 

$time_start = getmicrotime();

IF(!isset($paramYear)){
    $paramYear = date("Y");
}
IF(!isset($paramMonth)){
    $paramMonth = date("n");
}

$month = addslashes($paramMonth - 1);
$year = addslashes($paramYear);


for($i = 0; $i < sizeof($this->eventsEntries); $i++)
{
    $day = $this->eventsEntries[$i]->event_day;
    $event_id = $this->eventsEntries[$i]->event_id;
    $events[$day][] = $this->eventsEntries[$i]->event_id;
    $event_info[$event_id]['0'] = mb_substr($this->eventsEntries[$i]->event_title, 0, 8, 'utf8');
    $event_info[$event_id]['1'] = $this->eventsEntries[$i]->event_time;
}

$todays_year = date("Y");
$todays_date = date("j");
$todays_month = date("n");

$days_in_month = date ("t", mktime(0,0,0,$paramMonth,0,$paramYear));
$first_day_of_month = date ("w", mktime(0,0,0,$paramMonth-1,1,$paramYear));
$first_day_of_month = $first_day_of_month + 1;
$count_boxes = 0;
$days_so_far = 0;

IF($paramMonth == 13){
    $next_month = 2;
    $next_year = $paramYear + 1;
} ELSE {
    $next_month = $paramMonth + 1;
    $next_year = $paramYear;
}

IF($paramMonth == 2){
    $prev_month = 13;
    $prev_year = $paramYear - 1;
} ELSE {
    $prev_month = $paramMonth - 1;
    $prev_year = $paramYear;
}



?>
<link href="/css/calendar.css" rel="stylesheet" type="text/css">
<script language="JavaScript" type="text/JavaScript">
<!--
function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}
function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}
//-->

$(document).ready(function(){
	$('#btnAddEvent').live('click', function(){
        $.blockUI({ 
            message: $("#divAddEvent"),
            fadeIn: 500, 
            fadeOut: 500,
            css: { 
                width: '400px',
                cursor: 'auto',
                '-webkit-border-radius': '10px', 
                '-moz-border-radius': '10px'
            } 
        });
    });
   	
	$('#btnCancelAdd').click(function(){
    	$.unblockUI(); 
    });

	$('#btnDelEvent').click(function() {
		$('.chkDelEvent').show();
        $('#btnCfmDelEvent').show();
    	$('#btnCancelDel').show();
    });    

    $('#btnCancelDel').click(function(){
    	$('.chkDelEvent').removeAttr('checked');
    	$('.chkDelEvent').hide();
        $('#btnCfmDelEvent').hide();
        $('#btnCancelDel').hide();
    });

    $('#btnCfmDelEvent').live('click', function(){
    	if(confirm('確認刪除已選取的行程?')){
        	return true;
    	}
    	else{
        	return false;
    	}
    });
	
	$("#txtDeparture").datepicker({changeYear: false, changeMonth : false,  dateFormat: 'yy-mm-dd', yearRange: "-5:+5"});
	$("#txtReturn").datepicker({changeYear: false, changeMonth : false,  dateFormat: 'yy-mm-dd', yearRange: "-5:+5"});
});
</script>
<div id="global">
	<?php require_once '/template/left-sidebar.phtml';?>
	<div id="content-with-oneside">
		<div>
			<input id="btnAddEvent" type="button" value="<?php echo $this->addEvent;?>"/>
			<input id="btnDelEvent" type="button" value="<?php echo $this->delEvent;?>"/>
		</div>
		<div align="center">
			<span class="currentdate"><? echo date ("F Y", mktime(0,0,0,$paramMonth-1,1,$paramYear)); ?></span>
		</div>
		<div align="center"><br>
		  <table width="700" border="0" cellspacing="0" cellpadding="0">
		    <tr> 
		      <td><div align="right"><a href="<?php echo "/member/schedule/month/" . $prev_month . "/year/" . $prev_year; ?>">&lt;&lt;</a></div></td>
		      <td width="200"><div align="center">
		            
		          <select name="month" id="month" onChange="MM_jumpMenu('parent',this,0)">
		            <?php
					for ($i = 1; $i <= 12; $i++) {
						$link = $i;
						IF($paramMonth == $link){
							$selected = "selected";
						} ELSE {
							$selected = "";
						}
						echo "<option value='/member/schedule/month/" . $link . "/year/" . $paramYear . "' " . $selected . ">" . date ("F", mktime(0,0,0,$i,1,$paramYear)) . "</option>\n";
					}
					?>
		          </select>
		          <select name="year" id="year" onChange="MM_jumpMenu('parent',this,0)">
				  <?php
				  for ($i = 2011; $i <= 2015; $i++) {
				  	IF($i == $paramYear){
						$selected = "selected";
					} ELSE {
						$selected = "";
					}
				  	echo "<option value='/member/schedule/month/" . $paramMonth . "/year/" . $i . "' " . $selected . ">" . $i . "</option>\n";
				  }
				  ?>
		          </select>
		        </div></td>
		      <td><div align="left"><a href="<?php echo "/member/schedule/month/" . $next_month . "/year/" . $next_year; ?>">&gt;&gt;</a></div></td>
		    </tr>
		  </table>
		  <br>
		</div>
		<form id="delEventForm" method='post' action='<?php echo $this->escape($this->delAction);?>' enctype='multipart/form-data'>
			<input id="btnCfmDelEvent" type="submit" style="display:none;" value="<?php echo $this->cfmDelEvent;?>"/>
			<input id="btnCancelDel" type="button" style="display:none;" value="<?php echo $this->cancel;?>"/>
			<table id="tblCalendar" width="700" border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#000000">
			  <tr>
			    <td><table width="100%" border="0" cellpadding="0" cellspacing="1">
			        <tr class="topdays"> 
			          <td><div align="center"><?php echo $this->escape($this->sunday);?></div></td>
			          <td><div align="center"><?php echo $this->escape($this->monday);?></div></td>
			          <td><div align="center"><?php echo $this->escape($this->tuesday);?></div></td>
			          <td><div align="center"><?php echo $this->escape($this->wednesday);?></div></td>
			          <td><div align="center"><?php echo $this->escape($this->thursday);?></div></td>
			          <td><div align="center"><?php echo $this->escape($this->friday);?></div></td>
			          <td><div align="center"><?php echo $this->escape($this->saturday);?></div></td>
			        </tr>
					<tr valign="top" bgcolor="#FFFFFF"> 
					<?php
					for ($i = 1; $i <= $first_day_of_month-1; $i++) {
						$days_so_far = $days_so_far + 1;
						$count_boxes = $count_boxes + 1;
						echo "<td width=\"100\" height=\"100\" class=\"beforedayboxes\"></td>\n";
					}
					for ($i = 1; $i <= $days_in_month; $i++) {
			   			$days_so_far = $days_so_far + 1;
			    			$count_boxes = $count_boxes + 1;
			    		IF($paramMonth == $todays_month+1 && $paramYear == $todays_year){
							IF($paramMonth == $todays_month+1){
								IF($i == $todays_date){
									$class = "highlighteddayboxes";
								} ELSE {
									$class = "dayboxes";
								}
							} ELSE {
								IF($i == 1){
									$class = "highlighteddayboxes";
								} ELSE {
									$class = "dayboxes";
								}
							}
			    		}
			    		ELSE{
			    			$class = "dayboxes";
			    		}
						echo "<td width=\"100\" height=\"100\" class=\"$class\">\n";
						$link_month = $paramMonth - 1;
						echo "<div align=\"right\"><span class=\"toprightnumber\">\n<a href=\"javascript:MM_openBrWindow('event_add.php?day=$i&amp;month=$link_month&amp;year=$paramYear','','width=500,height=300');\">$i</a>&nbsp;</span></div>\n";
	
						IF(isset($events[$i])){
							echo "<div align=\"left\"><span class=\"eventinbox\">\n";
							while (list($key, $value) = each ($events[$i])) {
								echo "<input class='chkDelEvent' name='event_id[]' style='display:none;' type='checkbox' value='" . $value . "'>";
								echo "&nbsp;<a href=''>" . $event_info[$value]['1'] . " " . $event_info[$value]['0']  . "</a>\n<br>\n";
							}
							echo "</span></div>\n";
						}
						echo "</td>\n";
						IF(($count_boxes == 7) AND ($days_so_far != (($first_day_of_month-1) + $days_in_month))){
							$count_boxes = 0;
							echo "</TR><TR valign=\"top\">\n";
						}
					}
					$extra_boxes = 7 - $count_boxes;
					for ($i = 1; $i <= $extra_boxes; $i++) {
						echo "<td width=\"100\" height=\"100\" class=\"afterdayboxes\"></td>\n";
					}
					$time_end = getmicrotime();
					$time = round($time_end - $time_start, 3);
					?>
			        </tr>
			      </table></td>
			  </tr>
			</table>
		</form>
	</div>
</div>
<div id="divAddEvent" class="blockUI">
	<div class="header"><?php echo $this->addEvent;?></div>
	<form id="addEventForm" method='post' action='<?php echo $this->escape($this->addAction);?>' enctype='multipart/form-data'>
		<table>
			<tr>
				<td><?php echo $this->departure;?></td>
				<td>
					<input type='text' name='departure' id='txtDeparture' />
					<select name='departure_hour'>
						<?php 
							$open_hour = substr($this->escape($entry->open_time),0,2);
							for($i=0; $i<=23; $i++){
								$hour = $i;
								if(strlen($i)==1){
									$hour = '0' . $i;
								}
								if($open_hour == $hour){
									echo "<option value='" . $hour . "' selected>" . $hour . "</option>";
								}
								else{
									echo "<option value='" . $hour . "'>" . $hour . "</option>";
								}
							}
						?>				
					</select>
					<select name='departure_minute'>
						<?php 
							$open_minute = substr($this->escape($entry->open_time),3,2);
							for($i=0; $i<=59; $i++){
								$minute = $i;
								if(strlen($i)==1){
									$minute = '0' . $i;
								}
								if($open_minute == $minute){
									echo "<option value='" . $minute . "' selected>" . $minute . "</option>";
								}
								else{
									echo "<option value='" . $minute . "'>" . $minute . "</option>";
								}
							}
						?>
					</select>
				</td>
			</tr>
			<tr>
				<td><?php echo $this->turnBack;?></td>
				<td>
					<input type='text' name='return' id='txtReturn' />
					<select name='return_hour'>
						<?php 
							$open_hour = substr($this->escape($entry->open_time),0,2);
							for($i=0; $i<=23; $i++){
								$hour = $i;
								if(strlen($i)==1){
									$hour = '0' . $i;
								}
								if($open_hour == $hour){
									echo "<option value='" . $hour . "' selected>" . $hour . "</option>";
								}
								else{
									echo "<option value='" . $hour . "'>" . $hour . "</option>";
								}
							}
						?>				
					</select>
					<select name='return_minute'>
						<?php 
							$open_minute = substr($this->escape($entry->open_time),3,2);
							for($i=0; $i<=59; $i++){
								$minute = $i;
								if(strlen($i)==1){
									$minute = '0' . $i;
								}
								if($open_minute == $minute){
									echo "<option value='" . $minute . "' selected>" . $minute . "</option>";
								}
								else{
									echo "<option value='" . $minute . "'>" . $minute . "</option>";
								}
							}
						?>
					</select>
				</td>
			</tr>
			<tr>
				<td><?php echo $this->country;?></td>
				<td>
					<select name="country">
						<option value="">所有國家</option>
						<?php 
						for($i = 0;$i < sizeof($this->countryEntries); $i++){
						?>
						<option value="<?php echo $this->countryEntries[$i]->abbrev;?>"><?php echo $this->countryEntries[$i]->country_name;?></option>
						<?php 
						}
						?>
					</select>
				</td>
			</tr>
			<tr>
				<td></td>
				<td><input type="submit" value="<?php echo $this->submit;?>"/><input id="btnCancelAdd" type="button" value="<?php echo $this->cancel;?>"/></td>
			</tr>
		</table>
	</form>
</div>